import logging

import pytest

from resource.pom.gallery import Gallery
from resource.pom.launcher import Launcher


class Test:

    @pytest.mark.parametrize('setup_teardown', [None], indirect=True)
    def test(self, setup_teardown, device, factory_reset):
        logging.info('步骤1.长按图库')
        gallery_x, gallery_y = 296, 1143
        place_x, place_y = 77, 855
        for i in range(3):
            device.drag(gallery_x, gallery_y, place_x, place_y)
            device.refresh_layout()
            if device.get_element_by_text('图库'):
                break
        device.long_click(place_x, place_y)
        logging.info('预期结果1.正常弹出选项框')
        device.refresh_layout()
        device.assert_text_exist('打开')
        device.assert_text_exist('服务卡片')
        device.assert_text_exist('卡片中心')
        device.assert_text_exist('卸载')

        logging.info('步骤2.点击服务卡片')
        device.click_element(device.get_element_by_text('服务卡片'))
        logging.info('预期结果2.正常跳转到图库')
        device.assert_current_window(Launcher.form_manager_view)
        device.refresh_layout()
        device.assert_text_exist('添加到桌面')

        logging.info('步骤3.点击添加到桌面')
        device.click_element(device.get_element_by_text('添加到桌面'))
        logging.info('预期结果3.图库服务卡片成功添加到桌面')
        device.refresh_layout()
        device.assert_type_exist('FormComponent')

        logging.info('步骤4.点击服务卡片')
        device.click_element(device.get_element_by_type('FormComponent'))
        logging.info('预期结果4.成功跳转到图库内的照片详情页')
        device.assert_current_window(Gallery.window_name)
